﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebClient;
using DTO;
namespace WebClient.admin.Modules.customers
{
    public partial class Edit : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
            if (!this.IsPostBack)
            {
                InitItem();
            }
        }

        private void AddNew()
        {
            long id = -1;
            try
            {
                id = Convert.ToInt64(Request.Params["ID1"]);
            }
            catch { }
            WebData data = new WebData();
            Customers item = new Customers();
            item.fullname = this.txtfullname.Text.Trim();
            item.address = this.txtaddress.Text.Trim();
            item.phone = this.txtphone.Text.Trim();
            item.isActive = 1;//
            item.id = id;
            data.OnSubmitCustomers(item, 1);
        }
        private void InitItem()
        {
            ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
            WebData db = new WebData();
            Customers item = new Customers();
            long id = -1;
            try {
                id =Convert.ToInt64(Request.Params["ID1"]);
            }
            catch { }
            item = db.GetItemByIdCustomers(id);
            if (item != null)
            {
                txtfullname.Text = item.fullname.ToString();
                txtaddress.Text = item.address.ToString();
                txtphone.Text = item.phone.ToString();        
            }

        }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            AddNew();
        }
    }
}